package com.annhoa.infrastructure.interceptor;

import java.util.Arrays;
import java.util.logging.Logger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author annhoa 该方法用于注册拦截器 可注册多个拦截器，多个拦截器组成一个拦截器链 // extends
 *         WebMvcConfigurationSupport 实现出现静态资源拦截
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

	private Logger logger = Logger.getLogger(InterceptorConfig.class.toString());

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		logger.warning("进入拦截器！");
		registry.addInterceptor(new Interceptor()).addPathPatterns("/**")
				.excludePathPatterns(Arrays.asList("/staitc/**", "/templates/**", "/auth/login"));
		// 签名校验
		registry.addInterceptor(getParameterInterceptor()).addPathPatterns("/open-api/**");
	}


	@Bean
	public SignatureInInterceptor getParameterInterceptor(){
		return new SignatureInInterceptor();
	}

}
